from mq.RabbitMQ import RabbitMQ
from system.SystemInfo import SystemInfo
from work.HeartCheck import HeartCheck
from work.LogTransfer import LogTransfer
from work.ReceiveCMD import ReceiveCMD
from encryption.EncryptionUtils import EncryptionUtils

if __name__ == '__main__':
    print("Agent启动............")
    print("Agent开始获取系统信息............")
    # 实例化这个类
    system_info = SystemInfo()
    encryptor = EncryptionUtils()
    sys_info_data = system_info.get_info()
    print(sys_info_data)

    # 实例化 MQ
    rabbitmq = RabbitMQ()
    rabbitmq.produce_sysinfo(sys_info_data)
    print("Agent开始同步系统信息............")
    print("Agent发送心跳维持信息............")
    # 获取mac地址
    mac_address = system_info.get_mac_address()
    #  实例化心跳
    heart_check = HeartCheck(mac_address, rabbitmq)
    heart_check.start()

    print("Agent同步完成............")
    # 开始消费队列中的消息
    print("Agent准备接收消息............")
    rabbitmq = RabbitMQ()
    receive_cmd = ReceiveCMD(rabbitmq, mac_address)
    receive_cmd.start()
    # 根据状态文件启动日志同步服务
    if rabbitmq.log_sync_status:
        rabbitmq.log_transfer = LogTransfer(rabbitmq, mac_address)
        rabbitmq.log_transfer.start_sync()